Conditions | 1 |
Paths | 1 |
Total Lines | 260 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 4 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | var chai = require('chai'); |
||
18 | describe('cmsTemplates.prepare', function() { |
||
19 | before( function(done) { |
||
20 | Manager.instance.init() |
||
21 | .then(function () { |
||
22 | this.fixture = { |
||
23 | visibleTrue: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-visible-true.html'), 'utf-8'), |
||
24 | visibleFalse: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-visible-false.html'), 'utf-8'), |
||
25 | text: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-text.html'), 'utf-8'), |
||
26 | attribute: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-attribute.html'), 'utf-8'), |
||
27 | attributeConcat: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-attribute-concat.html'), 'utf-8'), |
||
28 | attributeMultiple: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-attribute-multiple.html'), 'utf-8'), |
||
29 | source: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-source.html'), 'utf-8'), |
||
30 | each: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each.html'), 'utf-8'), |
||
31 | eachMultiple: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each-multiple.html'), 'utf-8'), |
||
32 | eachVariable: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-abe-each-variable.html'), 'utf-8'), |
||
33 | rawHandlebar: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-raw-handlebars.html'), 'utf-8'), |
||
34 | noHtml: fse.readFileSync(path.join(process.cwd(), 'test', 'fixtures', 'templates', 'prepare-tag-nohtml.html'), 'utf-8') |
||
35 | } |
||
36 | done() |
||
37 | |||
38 | }.bind(this)) |
||
39 | }); |
||
40 | |||
41 | /** |
||
42 | * cmsTemplates.template.addAbeDataAttrForHtmlTag |
||
43 | * |
||
44 | */ |
||
45 | it('cmsTemplates.prepare.addAbeDataAttrForHtmlTag()', function() { |
||
46 | // stub |
||
47 | |||
48 | // test |
||
49 | var template = cmsTemplates.prepare.addAbeDataAttrForHtmlTag(this.fixture.text) |
||
50 | chai.expect(template.indexOf('<span data-abe-text_visible="text_visible" >')).to.be.above(-1); |
||
51 | |||
52 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlTag(this.fixture.each) |
||
53 | chai.expect(template.indexOf('data-abe-test{{@index}}-title="test{{@index}}-title"')).to.be.above(-1) |
||
54 | |||
55 | // |
||
56 | try{ |
||
57 | template = cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags(this.fixture.noHtml) |
||
58 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlTag(template) |
||
59 | } catch (e) { |
||
60 | console.log(e.stack) |
||
|
|||
61 | } |
||
62 | chai.expect(template.indexOf('"<abe data-abe-stores{{@index}}-lat="stores{{@index}}-lat"')).to.be.above(-1) |
||
63 | chai.expect(template.indexOf('<abe data-abe-stores2{{@index}}-lat="stores2{{@index}}-lat" >')).to.be.above(-1) |
||
64 | chai.expect(template.indexOf('<abe data-abe-text2="text2" >{{abe type="text" key="text2" desc="name"}}</abe>')).to.be.above(-1) |
||
65 | chai.expect(template.indexOf('"<abe data-abe-text3="text3" >{{abe type="text" key="text3" desc="name"}}</abe>"')).to.be.above(-1) |
||
66 | }); |
||
67 | |||
68 | /** |
||
69 | * cmsTemplates.template.getAbeAttributeData |
||
70 | * |
||
71 | */ |
||
72 | it('cmsTemplates.prepare.getAbeAttributeData()', function() { |
||
73 | // stub |
||
74 | |||
75 | // test |
||
76 | var template = cmsTemplates.prepare.getAbeAttributeData( |
||
77 | this.fixture.attribute, |
||
78 | "src=\"{{abe type='image' key='image_key' tab='default'}}\"", |
||
79 | "src", |
||
80 | "{{abe type='image' key='image_key' tab='default'}}" |
||
81 | ) |
||
82 | chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
||
83 | }); |
||
84 | |||
85 | /** |
||
86 | * cmsTemplates.template.addHasAbeAttr |
||
87 | * |
||
88 | */ |
||
89 | it('cmsTemplates.prepare.addHasAbeAttr()', function() { |
||
90 | // stub |
||
91 | |||
92 | // test |
||
93 | var template = cmsTemplates.prepare.addHasAbeAttr("}}") |
||
94 | chai.expect(template.indexOf('has-abe=1}}')).to.be.above(-1); |
||
95 | }); |
||
96 | |||
97 | /** |
||
98 | * cmsTemplates.template.addAbeDataAttrForHtmlAttributes |
||
99 | * |
||
100 | */ |
||
101 | it('cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes()', function() { |
||
102 | // stub |
||
103 | |||
104 | // test |
||
105 | var template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attribute) |
||
106 | chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
||
107 | |||
108 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attributeConcat) |
||
109 | chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
||
110 | |||
111 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.attributeMultiple) |
||
112 | chai.expect(template.indexOf('data-abe-attr-image_key="src" data-abe-image_key="image_key"')).to.be.above(-1); |
||
113 | chai.expect(template.indexOf('data-abe-attr-alternate="alt" data-abe-alternate="alternate" alt="mon alt')).to.be.above(-1); |
||
114 | |||
115 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.each) |
||
116 | chai.expect(template.indexOf('data-abe-attr-test[index].img="src" data-abe-test[index].img="test[index].img" data-abe-attr-test{{@index}}.img="src" data-abe-test{{@index}}.img="test[index].img" src="')).to.be.above(-1); |
||
117 | |||
118 | template = cmsTemplates.prepare.addAbeDataAttrForHtmlAttributes(this.fixture.eachMultiple) |
||
119 | chai.expect(template.indexOf('data-abe-attr-test[index].img="src" data-abe-test[index].img="test[index].img" data-abe-attr-test{{@index}}.img="src" data-abe-test{{@index}}.img="test[index].img" src="')).to.be.above(-1); |
||
120 | chai.expect(template.indexOf('data-abe-attr-test[index].alternate="alt" data-abe-test[index].alternate="test[index].alternate" data-abe-attr-test{{@index}}.alternate="alt" data-abe-test{{@index}}.alternate="test[index].alternate" alt="')).to.be.above(-1); |
||
121 | }); |
||
122 | |||
123 | /** |
||
124 | * cmsTemplates.template.addAbeSourceComment |
||
125 | * |
||
126 | */ |
||
127 | it('cmsTemplates.prepare.addAbeSourceComment()', function() { |
||
128 | var template = cmsTemplates.prepare.addAbeSourceComment(this.fixture.source, |
||
129 | { |
||
130 | abe_source: { |
||
131 | data_key: [{title: "test"}] |
||
132 | } |
||
133 | } |
||
134 | ) |
||
135 | |||
136 | chai.expect(template.indexOf('<!-- [[')).to.be.above(-1); |
||
137 | chai.expect(template.indexOf('-->')).to.be.above(-1); |
||
138 | }); |
||
139 | |||
140 | it('cmsTemplates.prepare.addAbeSourceComment() each', function() { |
||
141 | var template = cmsTemplates.prepare.addAbeSourceComment(this.fixture.each, { |
||
142 | abe_source: { |
||
143 | test: [{title: "test"}] |
||
144 | } |
||
145 | }) |
||
146 | |||
147 | chai.expect(template.indexOf('<!-- [[')).to.be.above(-1); |
||
148 | chai.expect(template.indexOf('-->')).to.be.above(-1); |
||
149 | }); |
||
150 | |||
151 | it('cmsTemplates.prepare.addAbeSourceComment() eachMultiple', function() { |
||
152 | var template = cmsTemplates.prepare.addAbeSourceComment(this.fixture.eachMultiple, { |
||
153 | abe_source: { |
||
154 | test: [{title: "test"}] |
||
155 | } |
||
156 | }) |
||
157 | |||
158 | chai.expect(template.indexOf('<!-- [[')).to.be.above(-1); |
||
159 | chai.expect(template.indexOf('-->')).to.be.above(-1); |
||
160 | }); |
||
161 | |||
162 | it('cmsTemplates.prepare.addAbeSourceComment() eachVariable', function() { |
||
163 | var template = cmsTemplates.prepare.addAbeSourceComment(this.fixture.eachVariable, { |
||
164 | abe_source: { |
||
165 | test: [{title: "test"}] |
||
166 | } |
||
167 | }) |
||
168 | |||
169 | chai.expect(template.indexOf('<!-- [[')).to.be.above(-1); |
||
170 | chai.expect(template.indexOf('-->')).to.be.above(-1); |
||
171 | }); |
||
172 | |||
173 | /** |
||
174 | * cmsTemplates.template.addAbeHtmlTagBetweenAbeTags |
||
175 | * |
||
176 | */ |
||
177 | it('cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags()', function() { |
||
178 | // stub |
||
179 | |||
180 | // test |
||
181 | var template = cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags(this.fixture.text) |
||
182 | chai.expect(template.indexOf('<abe>{{')).to.be.above(-1); |
||
183 | chai.expect(template.indexOf('}}</abe>')).to.be.above(-1); |
||
184 | |||
185 | template = cmsTemplates.prepare.addAbeHtmlTagBetweenAbeTags(this.fixture.noHtml) |
||
186 | chai.expect(template.indexOf('"lat": "<abe>{{abe type="text" key="stores.lat" desc="lat"}}</abe>"')).to.be.above(-1) |
||
187 | chai.expect(template.indexOf('<abe>{{abe type="text" key="stores2.lat" desc="lat"}}</abe>')).to.be.above(-1) |
||
188 | chai.expect(template.indexOf('<abe>{{abe type="text" key="text2" desc="name"}}</abe>')).to.be.above(-1) |
||
189 | chai.expect(template.indexOf('"<abe>{{abe type="text" key="text3" desc="name"}}</abe>"')).to.be.above(-1) |
||
190 | |||
191 | }); |
||
192 | |||
193 | /** |
||
194 | * cmsTemplates.template.replaceAbeEachIndex |
||
195 | * |
||
196 | */ |
||
197 | it('cmsTemplates.prepare.replaceAbeEachIndex()', function() { |
||
198 | var template = cmsTemplates.prepare.replaceAbeEachIndex('[index].') |
||
199 | chai.expect(template).to.be.equal('{{@index}}-'); |
||
200 | }); |
||
201 | |||
202 | /** |
||
203 | * cmsTemplates.template.removeHiddenAbeTag |
||
204 | * |
||
205 | */ |
||
206 | it('cmsTemplates.prepare.removeHiddenAbeTag()', function() { |
||
207 | var template = cmsTemplates.prepare.removeHiddenAbeTag(this.fixture.visibleFalse) |
||
208 | chai.expect(template).to.be.equal(""); |
||
209 | |||
210 | var template2 = cmsTemplates.prepare.removeHiddenAbeTag(this.fixture.visibleTrue) |
||
211 | chai.expect(template2.indexOf('{{abe')).to.be.above(-1); |
||
212 | }); |
||
213 | |||
214 | /** |
||
215 | * cmsTemplates.template.removeHandlebarsRawFromHtml |
||
216 | * |
||
217 | */ |
||
218 | it('cmsTemplates.prepare.removeHandlebarsRawFromHtml()', function() { |
||
219 | var template = cmsTemplates.prepare.removeHandlebarsRawFromHtml(this.fixture.rawHandlebar) |
||
220 | chai.expect(template).to.be.equal("test"); |
||
221 | }); |
||
222 | |||
223 | /** |
||
224 | * cmsTemplates.template.splitEachBlocks |
||
225 | * |
||
226 | */ |
||
227 | it('cmsTemplates.prepare.splitEachBlocks()', function() { |
||
228 | var blocks = cmsTemplates.prepare.splitEachBlocks(this.fixture.each) |
||
229 | chai.expect(blocks.length).to.be.above(0); |
||
230 | }); |
||
231 | |||
232 | /** |
||
233 | * cmsTemplates.template.indexEachBlocks |
||
234 | * |
||
235 | */ |
||
236 | it('cmsTemplates.prepare.indexEachBlocks() each', function() { |
||
237 | var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.each, {}, false) |
||
238 | chai.expect(template.indexOf('abe dictionnary=')).to.be.above(-1) |
||
239 | }); |
||
240 | |||
241 | it('cmsTemplates.prepare.indexEachBlocks() eachMultiple', function() { |
||
242 | var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.eachMultiple, {}, false) |
||
243 | chai.expect(template.indexOf('abe dictionnary=')).to.be.above(-1) |
||
244 | }); |
||
245 | |||
246 | it('cmsTemplates.prepare.indexEachBlocks() eachMultiple with data', function() { |
||
247 | var template = cmsTemplates.prepare.indexEachBlocks( |
||
248 | this.fixture.eachMultiple, |
||
249 | { |
||
250 | abe_source: { |
||
251 | test: [{title: "test"}] |
||
252 | } |
||
253 | }, |
||
254 | false |
||
255 | ) |
||
256 | chai.expect(template.indexOf('abe dictionnary=')).to.be.above(-1) |
||
257 | chai.expect(template.indexOf('<!-- [[')).to.be.equal(-1); |
||
258 | }); |
||
259 | |||
260 | it('cmsTemplates.prepare.indexEachBlocks() eachVariable', function() { |
||
261 | var template = cmsTemplates.prepare.indexEachBlocks(this.fixture.eachVariable, {}, false) |
||
262 | chai.expect(template.indexOf('abe dictionnary=')).to.be.above(-1) |
||
263 | chai.expect(template.indexOf('{{formatted_address}} - (lat:{{geometry.location.lat}}-lng:{{geometry.location.lng}})')).to.be.above(-1) |
||
264 | }); |
||
265 | |||
266 | /** |
||
267 | * cmsTemplates.template.addAbeDictionnary |
||
268 | * |
||
269 | */ |
||
270 | it('cmsTemplates.prepare.addAbeDictionnary()', function() { |
||
271 | // stub |
||
272 | |||
273 | // test |
||
274 | var template = cmsTemplates.prepare.addAbeDictionnary(this.fixture.each, "{{abe type='text' key='test.title' desc='test title' tab='default'}}", 'test') |
||
275 | chai.expect(template.indexOf("abe dictionnary='test'")).to.be.above(-1); |
||
276 | }); |
||
277 | }); |
||
278 |